<template>
  <div>
    <el-row class="home" :gutter="30">
      <el-col :span="8">
        <el-card shadow="hover">
          <div class="user">
            <div class="ib">
              <img src="../../assets/logo.jpg" />
            </div>

            <div class="userinfo">
              <h3 class="name">Admin</h3>
              <p class="access">超级管理员</p>
            </div>
          </div>
          <hr />

          <div class="login-info">
            <p>
              上次登录时间:
              <span>2021-7-19</span>
            </p>
            <p>
              上次登录地点:
              <span>广州</span>
            </p>
          </div>
        </el-card>

        <!-- 表格区域 -->
        <el-card style="margin-top: 10px" shadow="hover">
          <div id="table2" style="height: 460px; width: 100%"></div>
        </el-card>
      </el-col>

      <el-col :span="16">
        <!-- 订单上面 -->
        <div class="num">
          <el-card
            v-for="(item, index) in countdata"
            :key="index"
            :body-style="{ padding: 0 }"
            shadow="hover"
          >
            <div class="ll">
              <i
                class="icon"
                :class="`el-icon-${item.icon}`"
                :style="{ background: item.color }"
              ></i>
              <div class="detail">
                <p class="num">{{ item.value }}</p>
                <p class="txt">{{ item.name }}</p>
              </div>
            </div>
          </el-card>
        </div>

        <el-card shadow="hover">
          <div id="table1" style="height: 170px; width: 100%"></div>
        </el-card>
        <!-- 右下方图表设计 -->
        <div class="graph">
          <el-card shadow="hover">
            <div id="table3" class="tz"></div>
          </el-card>
          <el-card shadow="hover">
            <div id="table4" class="tz"></div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from "echarts";
import "echarts-gl";
export default {
  name: "",
  created() {
    console.log("当前路由", this.$route);
    let m = {};
    m.path = this.$route.path;
    m.name = this.$route.name;
    m.type = "";
    this.$store.commit("addrouterlist", m);
  },

  mounted() {
    this.init1();
    this.init2();
    this.init3();
    this.init4();
  },

  data() {
    return {
      tableitem: {
        ke: "课程",
        jnbuy: "今日购买",
        bbuy: "本月购买",
        zbuy: "总购买",
      },
      countdata: [
        {
          name: "今日支付订单",
          value: 1234,
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日收藏订单",
          value: 1234,
          icon: "star-on",
          color: "#ffb980",
        },
        {
          name: "今日未支付订单",
          value: 1234,
          icon: "s-goods",
          color: "#5ab1ef",
        },
        {
          name: "本月支付订单",
          value: 1234,
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "本月收藏订单",
          value: 1234,
          icon: "star-on",
          color: "#ffb980",
        },
        {
          name: "本月未支付订单",
          value: 1234,
          icon: "s-goods",
          color: "#5ab1ef",
        },
      ],
    };
  },

  methods: {
    // 图表1
    init1() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("table1"));
      // 绘制图表
      myChart.setOption({
        title: {
          text: "king",
        },
        tooltip: {},
        xAxis: {
          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        },
        yAxis: {},
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
          },
        ],
      });
    },
    // 图表2
    init2() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("table2"));
      // 绘制图表
      myChart.setOption({
        legend: {
          top: "bottom",
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        series: [
          {
            name: "Nightingale Chart",
            type: "pie",
            radius: [50, 250],
            center: ["50%", "50%"],
            roseType: "area",
            itemStyle: {
              borderRadius: 8,
            },
            data: [
              { value: 40, name: "rose 1" },
              { value: 38, name: "rose 2" },
              { value: 32, name: "rose 3" },
              { value: 30, name: "rose 4" },
              { value: 28, name: "rose 5" },
              { value: 26, name: "rose 6" },
              { value: 22, name: "rose 7" },
              { value: 18, name: "rose 8" },
            ],
          },
        ],
      });
    },
    // 图表3
    init3() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("table3"));
      // 绘制图表
      myChart.setOption({
        tooltip: {
          trigger: "item",
        },
        legend: {
          top: "5%",
          left: "center",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: 1048, name: "Search Engine" },
              { value: 735, name: "Direct" },
              { value: 580, name: "Email" },
              { value: 484, name: "Union Ads" },
              { value: 300, name: "Video Ads" },
            ],
          },
        ],
      });
    },
    // 图表4
    init4() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("table4"));
      var ROOT_PATH = "https://echarts.apache.org/examples";
      // 绘制图表
      myChart.setOption({
        title: {
          text: "Referer of a Website",
          subtext: "Fake Data",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "50%",
            data: [
              { value: 1048, name: "Search Engine" },
              { value: 735, name: "Direct" },
              { value: 580, name: "Email" },
              { value: 484, name: "Union Ads" },
              { value: 300, name: "Video Ads" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
    },
  },
};
</script>

<style scoped lang="less">
* {
  margin: 0px;
  padding: 0px;
}

.user {
  position: relative;
  margin-bottom: 15px;

  .ib {
    width: 100px;
    height: 100px;
    border-radius: 55px;
    overflow: hidden;

    img {
      width: 100px;
      height: 100px;
    }
  }

  .userinfo {
    position: absolute;
    left: 150px;
    top: 20px;
  }
}

.login-info {
  margin-top: 15px;

  span {
    margin-left: 40px;
  }
}

.num {
  display: flex;
  flex-wrap: wrap;
  padding: 0px;
  margin: 0px;

  .el-card {
    width: 280px;
    margin-right: 10px;
    margin-bottom: 15px;
    .ll {
      display: flex;
      i {
        height: 50px;
        line-height: 50px;
        text-align: center;
      }
    }

    .icon {
      height: 100%;
      width: 50px;
    }
  }
}

.graph {
  display: flex;

  .tz {
    width: 450px;
    height: 300px;
  }
  .el-card {
    margin-right: 35px;
    margin-top: 25px;
  }
}
</style>